var log = document.getElementById("log");
log.style.fontSize = document.body.clientHeight*0.015+"px"

function toBottom(){
	log.scrollTop = log.scrollHeight - log.clientHeight;
}

(function() {
	var old = console.log;
	var logger = document.getElementById('log');
	
	console.log = function(...args) {
		for(let i=0;i<args.length;i++){
			let message = args[i];
			if (typeof message == 'object') {
				logger.innerHTML += (JSON && JSON.stringify ? JSON.stringify(message) : message);
			} else {
				logger.innerHTML += message;
			}
		}
		logger.innerHTML += '<br />';
		
		toBottom();
	}
	
	console.error = function(...args) {
		for(let i=0;i<args.length;i++){
			let message = args[i];
			if (typeof message == 'object') {
				logger.innerHTML += (JSON && JSON.stringify ? JSON.stringify(message) : message);
			} else {
				logger.innerHTML += '<b style="color: #FF0000;">' + message + '</b>';
			}
			logger.innerHTML += '<br />';
		}
		
		toBottom();
	}
	
	window.οnerrοr=fnErrorTrap;
	function fnErrorTrap(sMsg,sUrl,sLine){
	logger.innerHTML="<b>An error was thrown and caught.</b><p>";
	logger.innerHTML+="Error: " + sMsg + "<br>";
	logger.innerHTML+="Line: " + sLine + "<br>";
	logger.innerHTML+="URL: " + sUrl + "<br>";
	return false;
	}

})();
